xlat v2: Cleanup get/change mem attr helpers
authorAntonio Nino Diaz <[email protected]>
Sun, 5 Aug 2018 14:34:10 +0000 (15:34 +0100)
committerAntonio Nino Diaz <[email protected]>
Mon, 6 Aug 2018 08:45:50 +0000 (09:45 +0100)
Changed the names for consistency with the rest of the library. Introduced
new helpers that manipulate the active translation tables context.

Change-Id: Icaca56b67fcf6a96e88aa3c7e47411162e8e6856
Signed-off-by: Antonio Nino Diaz <[email protected]>
include/lib/xlat_tables/xlat_tables_v2.h
lib/xlat_tables_v2/xlat_tables_context.c
lib/xlat_tables_v2/xlat_tables_utils.c
services/std_svc/spm/sp_xlat.c

index fd61fc40b1b6227da9f664f363f0c6fcb8250f50..022accee541bc046ff6dec579c1e8837355db95b 100644 (file)
@@ -296,14 +296,15 @@ int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx,
  * translation tables are not modified by any other code while this function is
  * executing.
  */
-int change_mem_attributes(const xlat_ctx_t *ctx, uintptr_t base_va, size_t size,
-                         uint32_t attr);
+int xlat_change_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
+                                  size_t size, uint32_t attr);
+int xlat_change_mem_attributes(uintptr_t base_va, size_t size, uint32_t attr);
 
 /*
  * Query the memory attributes of a memory page in a set of translation tables.
  *
  * Return 0 on success, a negative error code on error.
- * On success, the attributes are stored into *attributes.
+ * On success, the attributes are stored into *attr.
  *
  * ctx
  *   Translation context to work on.
@@ -311,11 +312,12 @@ int change_mem_attributes(const xlat_ctx_t *ctx, uintptr_t base_va, size_t size,
  *   Virtual address of the page to get the attributes of.
  *   There are no alignment restrictions on this address. The attributes of the
  *   memory page it lies within are returned.
- * attributes
+ * attr
  *   Output parameter where to store the attributes of the targeted memory page.
  */
-int get_mem_attributes(const xlat_ctx_t *ctx, uintptr_t base_va,
-                      uint32_t *attributes);
+int xlat_get_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
+                               uint32_t *attr);
+int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr);
 
 #endif /*__ASSEMBLY__*/
 #endif /* XLAT_TABLES_V2_H */
index d7b2ebf8dc9b284d89554592183455afab0c6f4e..143f08ab3e239e78b45dff88c4102945f172e634 100644 (file)
@@ -90,6 +90,16 @@ void init_xlat_tables(void)
        init_xlat_tables_ctx(&tf_xlat_ctx);
 }
 
+int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr)
+{
+       return xlat_get_mem_attributes_ctx(&tf_xlat_ctx, base_va, attr);
+}
+
+int xlat_change_mem_attributes(uintptr_t base_va, size_t size, uint32_t attr)
+{
+       return xlat_change_mem_attributes_ctx(&tf_xlat_ctx, base_va, size, attr);
+}
+
 /*
  * If dynamic allocation of new regions is disabled then by the time we call the
  * function enabling the MMU, we'll have registered all the memory regions to
index 0cbd45e400bfc3df361076bc3535445d269ffe9a..978a506c950c066a9f0d3c03e19f668ff050b1de 100644 (file)
@@ -314,8 +314,8 @@ static uint64_t *find_xlat_table_entry(uintptr_t virtual_addr,
 }
 
 
-static int get_mem_attributes_internal(const xlat_ctx_t *ctx, uintptr_t base_va,
-               uint32_t *attributes, uint64_t **table_entry,
+static int xlat_get_mem_attributes_internal(const xlat_ctx_t *ctx,
+               uintptr_t base_va, uint32_t *attributes, uint64_t **table_entry,
                unsigned long long *addr_pa, unsigned int *table_level)
 {
        uint64_t *entry;
@@ -407,18 +407,16 @@ static int get_mem_attributes_internal(const xlat_ctx_t *ctx, uintptr_t base_va,
 }
 
 
-int get_mem_attributes(const xlat_ctx_t *ctx, uintptr_t base_va,
-                      uint32_t *attributes)
+int xlat_get_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
+                               uint32_t *attr)
 {
-       return get_mem_attributes_internal(ctx, base_va, attributes,
-                                          NULL, NULL, NULL);
+       return xlat_get_mem_attributes_internal(ctx, base_va, attr,
+                               NULL, NULL, NULL);
 }
 
 
-int change_mem_attributes(const xlat_ctx_t *ctx,
-                       uintptr_t base_va,
-                       size_t size,
-                       uint32_t attr)
+int xlat_change_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
+                                  size_t size, uint32_t attr)
 {
        /* Note: This implementation isn't optimized. */
 
@@ -517,7 +515,7 @@ int change_mem_attributes(const xlat_ctx_t *ctx,
                unsigned int level = 0U;
                unsigned long long addr_pa = 0ULL;
 
-               (void) get_mem_attributes_internal(ctx, base_va, &old_attr,
+               (void) xlat_get_mem_attributes_internal(ctx, base_va, &old_attr,
                                            &entry, &addr_pa, &level);
 
                /*
index 2aa2fa135763a51a4178a7a098e2c3e8a3fe7555..3527138600c83f867f489311c3e29abf7993d3b9 100644 (file)
@@ -44,7 +44,7 @@ xlat_ctx_t *spm_get_sp_xlat_context(void)
  * converts an attributes value from the SMC format to the mmap_attr_t format by
  * setting MT_RW/MT_RO, MT_USER/MT_PRIVILEGED and MT_EXECUTE/MT_EXECUTE_NEVER.
  * The other fields are left as 0 because they are ignored by the function
- * change_mem_attributes().
+ * xlat_change_mem_attributes_ctx().
  */
 static unsigned int smc_attr_to_mmap_attr(unsigned int attributes)
 {
@@ -112,12 +112,12 @@ int32_t spm_memory_attributes_get_smc_handler(sp_context_t *sp_ctx,
 
        spin_lock(&mem_attr_smc_lock);
 
-       int rc = get_mem_attributes(sp_ctx->xlat_ctx_handle,
+       int rc = xlat_get_mem_attributes_ctx(sp_ctx->xlat_ctx_handle,
                                     base_va, &attributes);
 
        spin_unlock(&mem_attr_smc_lock);
 
-       /* Convert error codes of get_mem_attributes() into SPM ones. */
+       /* Convert error codes of xlat_get_mem_attributes_ctx() into SPM. */
        assert((rc == 0) || (rc == -EINVAL));
 
        if (rc == 0) {
@@ -142,13 +142,13 @@ int spm_memory_attributes_set_smc_handler(sp_context_t *sp_ctx,
 
        spin_lock(&mem_attr_smc_lock);
 
-       int ret = change_mem_attributes(sp_ctx->xlat_ctx_handle,
+       int ret = xlat_change_mem_attributes_ctx(sp_ctx->xlat_ctx_handle,
                                        base_va, size,
                                        smc_attr_to_mmap_attr(attributes));
 
        spin_unlock(&mem_attr_smc_lock);
 
-       /* Convert error codes of change_mem_attributes() into SPM ones. */
+       /* Convert error codes of xlat_change_mem_attributes_ctx() into SPM. */
        assert((ret == 0) || (ret == -EINVAL));
 
        return (ret == 0) ? SPM_SUCCESS : SPM_INVALID_PARAMETER;